package com.seo.service.keyword.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import org.springframework.stereotype.Service;

import com.seo.mapper.keyword.KeywordMapper;
import com.seo.mapper.proxy.ProxyUserMapper;
import com.seo.pojo.ReturnBody;
import com.seo.service.keyword.sdk.KeywordService;
import com.seo.service.user.sdk.UserService;
import com.seo.utils.CommonUtil;
import com.seo.utils.KeyWordsIndex;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service("keywordService")
public class KeywordServiceImpl implements KeywordService {

	private Map<String, KeywordServiceImpl> keywordServiceMap = new HashMap<>();

	@Autowired
	private KeywordMapper keywordMapper;

	@Autowired
	private UserService userService;

	@Autowired
	private ProxyUserMapper proxyUserMapper;

	@Value("${keyword.key}")
	private String key;
	@Value("${keyword.shenma.url}")
	private String shenmaUrl;
	@Value("${keyword.so.url}")
	private String soUrl;
	@Value("${keyword.sougou.url}")
	private String sougouUrl;
	@Value("${keyword.baidu.url}")
	private String baiduUrl;

	@PostConstruct
	public void init() {
		log.info("交叉上传注册[{}]", "01");
		keywordServiceMap.put("01", this);
	}

	@Override
	public List<Map<String, Object>> getKeyWordOffer(Map<String, Object> param) {
		List<Map<String, Object>> res = new ArrayList<>();
		if (param == null || param.isEmpty()) {
			return null;
		}
		String keyWord = param.get("keyWord") + "";
		String type = param.get("type") + "";
		Integer userId = Integer.parseInt(param.get("userId") + "");
		if (StringUtils.isEmpty(keyWord) || StringUtils.isEmpty(type)) {
			return null;
		}

		List<String> keyWords = CommonUtil.isKeywordGroup(keyWord, ",").getCollection("keywordList", String.class);
		String[] en = {"01", "02", "03", "04", "05", "06", "07"};
		if(keyWords != null && keyWords.size() > 0) {
			res = getKeyWordOffer(keyWords, type, userId, en);
		} else {
			res = null;
		}
		log.info("关键词报价结束--- res={}", res);
		return res;
	}
	
	@Override
	public List<Map<String, Object>> getKeyWordOffer1(Map<String, Object> param) {
		List<Map<String, Object>> res = new ArrayList<>();
		if (param == null || param.isEmpty()) {
			return null;
		}
		String keyWord = param.get("keyWord") + "";
		String type = param.get("type") + "";
		if (StringUtils.isEmpty(keyWord) || StringUtils.isEmpty(type)) {
			return null;
		}

		List<String> keyWords = CommonUtil.isKeywordGroup(keyWord, ",").getCollection("keywordList", String.class);
		if(keyWords != null && keyWords.size() > 0) {
			res = getKeyWordO(keyWords, param);
		} else {
			res = null;
		}
		
		log.info("关键词报价结束--- res={}", res);
		return res;
	}

	public List<Map<String, Object>> getKeyWordO(List<String> keyWords, Map<String, Object> param) {
		List<Map<String, Object>> res = new ArrayList<>();
		String price1 = param.get("price1") + "";
		String price2 = param.get("price2") + "";
		for (String kw : keyWords) {
			Map<String, Object> ko = new HashMap<>();
			int num = keywordMapper.getkeyWordConfig(kw);
			ko.put("keyWord", kw);
			if(num > 0) {
				ko.put("SogouMobile", price1);
				ko.put("shenma", price1);
				ko.put("BaiduMobile", price1);
				ko.put("BaiduPc", price1);
				ko.put("SogouPc", price1);
				ko.put("so", price1);
			} else {
				ko.put("SogouMobile", price2);
				ko.put("shenma", price2);
				ko.put("BaiduMobile", price2);
				ko.put("BaiduPc", price2);
				ko.put("SogouPc", price2);
				ko.put("so", price2);
			}
			res.add(ko);
		}
		return res;
	}

	/**
	 * 关键词报价
	 * 
	 * @param keyWord
	 *            关键词
	 * @param type
	 *            用户类型
	 * @return List<Map<String, Object>>
	 */
	@Override
	public List<Map<String, Object>> getKeyWordOffer(List<String> keyWords, String type, Integer userId, String[] engineCode) {
		log.info("关键词报价开始--- keyWord={}, type={}", keyWords, type);
		List<Map<String, Object>> res = new ArrayList<>();
		List<String> param = new ArrayList<>();
		if (StringUtils.isEmpty(key) || StringUtils.isEmpty(type) || engineCode == null || engineCode.length == 0) {
			return null;
		}
		try {
			for (int i = 0; i < engineCode.length; i++) {
				if("01".equals(engineCode[i]) || "02".equals(engineCode[i])) {
					param.add(baiduUrl);
				} else if("03".equals(engineCode[i]) || "04".equals(engineCode[i])) {
					param.add(soUrl);
				} else if("05".equals(engineCode[i])) {
					param.add(shenmaUrl);
				} else if("06".equals(engineCode[i]) || "07".equals(engineCode[i])) {
					param.add(sougouUrl);
				}
			}
			List<Map<String, Object>> keyWordsIndex = KeyWordsIndex.getKeyWordsIndex(keyWords, key, param);
			if (keyWordsIndex != null && keyWordsIndex.size() > 0) {
				List<Map<String, Object>> keyWordOffer = new ArrayList<>();
				if ("00".equals(type)) {
					keyWordOffer = keywordMapper.getKeyWordOffer();
				} else {
					if (userId == null || userId == 0) {
						return null;
					}
					keyWordOffer = keywordMapper.getKeyWordOfferProxy(userId);
				}
				int n = 0;
				for (Map<String, Object> maps : keyWordsIndex) {
					Map<String, Object> ko = new HashMap<>();
					int num = keywordMapper.getkeyWordConfig(keyWords.get(n));
					int nums = 0;
					if (keyWordOffer != null && keyWordOffer.size() > 0) {
						for (Map<String, Object> map : keyWordOffer) {
							if (map != null && !map.isEmpty()) {
								String price1 = map.get("price_1") + "";
								String price2 = map.get("price_2") + "";
								if ("-1.0000".equals(price1) || "-1.0000".equals(price2)) {
									return null;
								}
								if (maps == null || maps.isEmpty()) {
									ko.put("keyWord", keyWords.get(n));
									ko = getZeroIndexOffer(keyWords.get(n), ko, keyWordOffer, num);
								} else {
									int minIndex = Integer.parseInt(map.get("min_index") + "");
									int maxIndex = Integer.parseInt(map.get("max_index") + "");
									int SogouMobile = 0;
									int shenma = 0;
									int BaiduMobile = 0;
									int BaiduPc = 0;
									int SogouPc = 0;
									int so = 0;
									if (maps.containsKey("SogouMobile")) {
										SogouMobile = Integer.parseInt(maps.get("SogouMobile") + "");
									}
									if (maps.containsKey("shenma")) {
										shenma = Integer.parseInt(maps.get("shenma") + "");
									}
									if (maps.containsKey("BaiduMobile")) {
										BaiduMobile = Integer.parseInt(maps.get("BaiduMobile") + "");
									}
									if (maps.containsKey("BaiduPc")) {
										BaiduPc = Integer.parseInt(maps.get("BaiduPc") + "");
									}
									if (maps.containsKey("SogouPc")) {
										SogouPc = Integer.parseInt(maps.get("SogouPc") + "");
									}
									if (maps.containsKey("so")) {
										so = Integer.parseInt(maps.get("so") + "");
									}
									ko.put("keyWord", keyWords.get(n));
									ko = getZeroIndexOffer(SogouMobile, shenma, BaiduMobile, BaiduPc, SogouPc, so,
											keyWords.get(n), ko, keyWordOffer, num);
									if (minIndex <= SogouMobile && SogouMobile <= maxIndex) {
										ko.put("SogouMobileI", SogouMobile);
										if (num > 0) {
											ko.put("SogouMobile", price1);
										} else {
											ko.put("SogouMobile", price2);
										}
									}
									if (minIndex <= shenma && shenma <= maxIndex) {
										ko.put("shenmaI", shenma);
										if (num > 0) {
											ko.put("shenma", price1);
										} else {
											ko.put("shenma", price2);
										}
									}
									if (minIndex <= BaiduMobile && BaiduMobile <= maxIndex) {
										ko.put("BaiduMobileI", BaiduMobile);
										if (num > 0) {
											ko.put("BaiduMobile", price1);
										} else {
											ko.put("BaiduMobile", price2);
										}
									}
									if (minIndex <= BaiduPc && BaiduPc <= maxIndex) {
										ko.put("BaiduPcI", BaiduPc);
										if (num > 0) {
											ko.put("BaiduPc", price1);
										} else {
											ko.put("BaiduPc", price2);
										}
									}
									if (minIndex <= SogouPc && SogouPc <= maxIndex) {
										ko.put("SogouPcI", SogouPc);
										if (num > 0) {
											ko.put("SogouPc", price1);
										} else {
											ko.put("SogouPc", price2);
										}
									}
									if (minIndex <= so && so <= maxIndex) {
										ko.put("soI", so);
										if (num > 0) {
											ko.put("so", price1);
										} else {
											ko.put("so", price2);
										}
									}
									if (nums == 5) {
										if (SogouMobile > 2000) {
											ko.put("SogouMobileI", SogouMobile);
											if (num > 0) {
												ko.put("SogouMobile", price1);
											} else {
												ko.put("SogouMobile", price2);
											}
										}
										if (shenma > 2000) {
											ko.put("shenmaI", shenma);
											if (num > 0) {
												ko.put("shenma", price1);
											} else {
												ko.put("shenma", price2);
											}
										}
										if (BaiduMobile > 2000) {
											ko.put("BaiduMobileI", BaiduMobile);
											if (num > 0) {
												ko.put("BaiduMobile", price1);
											} else {
												ko.put("BaiduMobile", price2);
											}
										}
										if (BaiduPc > 2000) {
											ko.put("BaiduPcI", BaiduPc);
											if (num > 0) {
												ko.put("BaiduPc", price1);
											} else {
												ko.put("BaiduPc", price2);
											}
										}
										if (SogouPc > 2000) {
											ko.put("SogouPcI", SogouPc);
											if (num > 0) {
												ko.put("SogouPc", price1);
											} else {
												ko.put("SogouPc", price2);
											}
										}
										if (so > 2000) {
											ko.put("soI", so);
											if (num > 0) {
												ko.put("so", price1);
											} else {
												ko.put("so", price2);
											}
										}
									}
									nums++;
								}
							}
						}
					} else {
						return null;
					}
					res.add(ko);
					n++;
				}
			} else {
				return null;
			}
		} catch (Exception e) {
			log.info("关键词报价异常--- e={}", e);
			return null;
		}
		return res;
	}

	private Map<String, Object> getZeroIndexOffer(String keyWord, Map<String, Object> ko,
			List<Map<String, Object>> keyWordOffer, int num) {
		ko.put("SogouMobileI", "-1");
		if (num > 0) {
			if (keyWord.length() == 3) {
				ko.put("SogouMobile", keyWordOffer.get(1).get("price_1"));
			} else if (keyWord.length() < 3) {
				ko.put("SogouMobile", keyWordOffer.get(2).get("price_1"));
			} else {
				ko.put("SogouMobile", keyWordOffer.get(0).get("price_1"));
			}
		} else {
			if (keyWord.length() == 3) {
				ko.put("SogouMobile", keyWordOffer.get(1).get("price_2"));
			} else if (keyWord.length() < 3) {
				ko.put("SogouMobile", keyWordOffer.get(2).get("price_2"));
			} else {
				ko.put("SogouMobile", keyWordOffer.get(0).get("price_2"));
			}
		}

		ko.put("shenmaI", "-1");
		if (num > 0) {
			if (keyWord.length() == 3) {
				ko.put("shenma", keyWordOffer.get(1).get("price_1"));
			} else if (keyWord.length() < 3) {
				ko.put("shenma", keyWordOffer.get(2).get("price_1"));
			} else {
				ko.put("shenma", keyWordOffer.get(0).get("price_1"));
			}
		} else {
			if (keyWord.length() == 3) {
				ko.put("shenma", keyWordOffer.get(1).get("price_2"));
			} else if (keyWord.length() < 3) {
				ko.put("shenma", keyWordOffer.get(2).get("price_2"));
			} else {
				ko.put("shenma", keyWordOffer.get(0).get("price_2"));
			}
		}

		ko.put("BaiduMobileI", "-1");
		if (num > 0) {
			if (keyWord.length() == 3) {
				ko.put("BaiduMobile", keyWordOffer.get(1).get("price_1"));
			} else if (keyWord.length() < 3) {
				ko.put("BaiduMobile", keyWordOffer.get(2).get("price_1"));
			} else {
				ko.put("BaiduMobile", keyWordOffer.get(0).get("price_1"));
			}
		} else {
			if (keyWord.length() == 3) {
				ko.put("BaiduMobile", keyWordOffer.get(1).get("price_2"));
			} else if (keyWord.length() < 3) {
				ko.put("BaiduMobile", keyWordOffer.get(2).get("price_2"));
			} else {
				ko.put("BaiduMobile", keyWordOffer.get(0).get("price_2"));
			}
		}

		ko.put("BaiduPcI", "-1");
		if (num > 0) {
			if (keyWord.length() == 3) {
				ko.put("BaiduPc", keyWordOffer.get(1).get("price_1"));
			} else if (keyWord.length() < 3) {
				ko.put("BaiduPc", keyWordOffer.get(2).get("price_1"));
			} else {
				ko.put("BaiduPc", keyWordOffer.get(0).get("price_1"));
			}
		} else {
			if (keyWord.length() == 3) {
				ko.put("BaiduPc", keyWordOffer.get(1).get("price_2"));
			} else if (keyWord.length() < 3) {
				ko.put("BaiduPc", keyWordOffer.get(2).get("price_2"));
			} else {
				ko.put("BaiduPc", keyWordOffer.get(0).get("price_2"));
			}
		}
		ko.put("SogouPcI", "-1");
		if (num > 0) {
			if (keyWord.length() == 3) {
				ko.put("SogouPc", keyWordOffer.get(1).get("price_1"));
			} else if (keyWord.length() < 3) {
				ko.put("SogouPc", keyWordOffer.get(2).get("price_1"));
			} else {
				ko.put("SogouPc", keyWordOffer.get(0).get("price_1"));
			}
		} else {
			if (keyWord.length() == 3) {
				ko.put("SogouPc", keyWordOffer.get(1).get("price_2"));
			} else if (keyWord.length() < 3) {
				ko.put("SogouPc", keyWordOffer.get(2).get("price_2"));
			} else {
				ko.put("SogouPc", keyWordOffer.get(0).get("price_2"));
			}
		}

		ko.put("soI", "-1");
		if (num > 0) {
			if (keyWord.length() == 3) {
				ko.put("so", keyWordOffer.get(1).get("price_1"));
			} else if (keyWord.length() < 3) {
				ko.put("so", keyWordOffer.get(2).get("price_1"));
			} else {
				ko.put("so", keyWordOffer.get(0).get("price_1"));
			}
		} else {
			if (keyWord.length() == 3) {
				ko.put("so", keyWordOffer.get(1).get("price_2"));
			} else if (keyWord.length() < 3) {
				ko.put("so", keyWordOffer.get(2).get("price_2"));
			} else {
				ko.put("so", keyWordOffer.get(0).get("price_2"));
			}
		}
		return ko;
	}

	private Map<String, Object> getZeroIndexOffer(int SogouMobile, int shenma, int BaiduMobile, int BaiduPc,
			int SogouPc, int so, String keyWord, Map<String, Object> ko, List<Map<String, Object>> keyWordOffer,
			int num) {
		if (SogouMobile == 0) {
			ko.put("SogouMobileI", SogouMobile);
			if (num > 0) {
				if (keyWord.length() == 3) {
					ko.put("SogouMobile", keyWordOffer.get(1).get("price_1"));
				} else if (keyWord.length() < 3) {
					ko.put("SogouMobile", keyWordOffer.get(2).get("price_1"));
				} else {
					ko.put("SogouMobile", keyWordOffer.get(0).get("price_1"));
				}
			} else {
				if (keyWord.length() == 3) {
					ko.put("SogouMobile", keyWordOffer.get(1).get("price_2"));
				} else if (keyWord.length() < 3) {
					ko.put("SogouMobile", keyWordOffer.get(2).get("price_2"));
				} else {
					ko.put("SogouMobile", keyWordOffer.get(0).get("price_2"));
				}
			}

		}
		if (shenma == 0) {
			ko.put("shenmaI", shenma);
			if (num > 0) {
				if (keyWord.length() == 3) {
					ko.put("shenma", keyWordOffer.get(1).get("price_1"));
				} else if (keyWord.length() < 3) {
					ko.put("shenma", keyWordOffer.get(2).get("price_1"));
				} else {
					ko.put("shenma", keyWordOffer.get(0).get("price_1"));
				}
			} else {
				if (keyWord.length() == 3) {
					ko.put("shenma", keyWordOffer.get(1).get("price_2"));
				} else if (keyWord.length() < 3) {
					ko.put("shenma", keyWordOffer.get(2).get("price_2"));
				} else {
					ko.put("shenma", keyWordOffer.get(0).get("price_2"));
				}
			}

		}
		if (BaiduMobile == 0) {
			ko.put("BaiduMobileI", BaiduMobile);
			if (num > 0) {
				if (keyWord.length() == 3) {
					ko.put("BaiduMobile", keyWordOffer.get(1).get("price_1"));
				} else if (keyWord.length() < 3) {
					ko.put("BaiduMobile", keyWordOffer.get(2).get("price_1"));
				} else {
					ko.put("BaiduMobile", keyWordOffer.get(0).get("price_1"));
				}
			} else {
				if (keyWord.length() == 3) {
					ko.put("BaiduMobile", keyWordOffer.get(1).get("price_2"));
				} else if (keyWord.length() < 3) {
					ko.put("BaiduMobile", keyWordOffer.get(2).get("price_2"));
				} else {
					ko.put("BaiduMobile", keyWordOffer.get(0).get("price_2"));
				}
			}

		}
		if (BaiduPc == 0) {
			ko.put("BaiduPcI", BaiduPc);
			if (num > 0) {
				if (keyWord.length() == 3) {
					ko.put("BaiduPc", keyWordOffer.get(1).get("price_1"));
				} else if (keyWord.length() < 3) {
					ko.put("BaiduPc", keyWordOffer.get(2).get("price_1"));
				} else {
					ko.put("BaiduPc", keyWordOffer.get(0).get("price_1"));
				}
			} else {
				if (keyWord.length() == 3) {
					ko.put("BaiduPc", keyWordOffer.get(1).get("price_2"));
				} else if (keyWord.length() < 3) {
					ko.put("BaiduPc", keyWordOffer.get(2).get("price_2"));
				} else {
					ko.put("BaiduPc", keyWordOffer.get(0).get("price_2"));
				}
			}
		}
		if (SogouPc == 0) {
			ko.put("SogouPcI", SogouPc);
			if (num > 0) {
				if (keyWord.length() == 3) {
					ko.put("SogouPc", keyWordOffer.get(1).get("price_1"));
				} else if (keyWord.length() < 3) {
					ko.put("SogouPc", keyWordOffer.get(2).get("price_1"));
				} else {
					ko.put("SogouPc", keyWordOffer.get(0).get("price_1"));
				}
			} else {
				if (keyWord.length() == 3) {
					ko.put("SogouPc", keyWordOffer.get(1).get("price_2"));
				} else if (keyWord.length() < 3) {
					ko.put("SogouPc", keyWordOffer.get(2).get("price_2"));
				} else {
					ko.put("SogouPc", keyWordOffer.get(0).get("price_2"));
				}
			}

		}
		if (so == 0) {
			ko.put("soI", so);
			if (num > 0) {
				if (keyWord.length() == 3) {
					ko.put("so", keyWordOffer.get(1).get("price_1"));
				} else if (keyWord.length() < 3) {
					ko.put("so", keyWordOffer.get(2).get("price_1"));
				} else {
					ko.put("so", keyWordOffer.get(0).get("price_1"));
				}
			} else {
				if (keyWord.length() == 3) {
					ko.put("so", keyWordOffer.get(1).get("price_2"));
				} else if (keyWord.length() < 3) {
					ko.put("so", keyWordOffer.get(2).get("price_2"));
				} else {
					ko.put("so", keyWordOffer.get(0).get("price_2"));
				}
			}

		}
		return ko;
	}

	@Override
	public List<Map<String, Object>> getEngineList() {
		return keywordMapper.getEngineList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public ReturnBody saveKeyWord(Map<String, Object> param, String type, String uploadType) {
		log.info("添加关键词开始--- param={}", param);
		ReturnBody rb = ReturnBody.init();
		if (param == null || param.isEmpty() || StringUtils.isEmpty(type)) {
			return rb.rollback("参数不能为空");
		}
		try {
			if ("01".equals(type)) {
				String userName = param.get("userName") + "";
				ReturnBody userByName = userService.getUserByName(userName);
				if (!userByName.isSuccess()) {
					return rb.rollback("用户不存在");
				} else {
					Map<String, Object> user = (Map<String, Object>) userByName.get("user");
					if (user != null) {
						if ("proxy".equals(user.get("roleCode"))) {
							param.put("user", user);
							rb.run(keywordServiceMap.get(uploadType).saveKeyWord1(param, "01"));
							return rb;
						} else {
							param.put("userId", user.get("id"));
							Map<String, Object> userById = userService
									.getUserById(Integer.parseInt(user.get("id") + ""));
							if (userById == null) {
								return rb.rollback("用户不存在");
							}
							String price1 = userById.get("price1") + "";
							String price2 = userById.get("price2") + "";
							if (!StringUtils.isEmpty(price1) && !"0.0000".equals(price1) && !StringUtils.isEmpty(price2)
									&& !"0.0000".equals(price2)) {
								param.put("user", user);
								rb.run(keywordServiceMap.get(uploadType).saveKeyWord1(param, "01"));
								return rb;
							}
						}
					}
				}
			} else {
				Map<String, Object> user = (Map<String, Object>) param.get("user");
				param.put("userId", user.get("id"));
				Map<String, Object> userById = userService.getUserById(Integer.parseInt(user.get("id") + ""));
				if (userById == null) {
					return rb.rollback("用户不存在");
				}
				String price1 = userById.get("price1") + "";
				String price2 = userById.get("price2") + "";
				if (!StringUtils.isEmpty(price1) && !"0.0000".equals(price1) && !StringUtils.isEmpty(price2)
						&& !"0.0000".equals(price2)) {
					param.put("user", user);
					rb.run(keywordServiceMap.get(uploadType).saveKeyWord1(param, "02"));
					return rb;
				}
			}
			rb.run(keywordServiceMap.get(uploadType).saveKeyWordAdmin(param));
			return rb;
		} catch (Exception e) {
			e.printStackTrace();
			log.info("添加关键词异常--- e={}", e);
			return rb.rollback("添加关键词异常");
		} finally {
			log.info("添加关键词结束--- res={}", rb);
			if (!rb.isSuccess()) {
				rb.result();
			}
		}
		
	}

	@SuppressWarnings("unchecked")
	public ReturnBody saveKeyWord1(Map<String, Object> param, String type) {
		log.info("代理用户添加关键词开始--- param={}", param);
		ReturnBody rb = ReturnBody.init();
		try {
			String keyWord = param.get("keyWord") + "";
			String domain = param.get("domain") + "";
			Map<String, Object> user = (Map<String, Object>) param.get("user");
			String createId = param.get("createId") + "";
			String engineCode = param.get("engineCode") + "";
			engineCode = engineCode.substring(0, engineCode.length() - 1);
			if (StringUtils.isEmpty(keyWord) || StringUtils.isEmpty(domain) || user == null
					|| StringUtils.isEmpty(createId) || StringUtils.isEmpty(engineCode)) {

				return rb.rollback("参数不能为空");
			}

			rb.run(CommonUtil.isUrlGroup(domain));

			if (!rb.isSuccess()) {
				rb.getResult().setIsRollBack("01");
				return rb;
			}
			rb.run(CommonUtil.isKeywordGroup(keyWord, "\n"));
			if (!rb.isSuccess()) {
				rb.getResult().setIsRollBack("01");
				return rb;
			}

			List<String> domains = rb.getCollection("urlList", String.class);
			String[] engineCodes = engineCode.split(",");
			List<String> keyWords = rb.getCollection("keywordList", String.class);
			Map<String, Object> userById = userService.getUserById(Integer.parseInt(user.get("id") + ""));
			if (userById == null) {
				return rb.rollback("用户不存在");
			}
			String price1 = userById.get("price1") + "";
			String price2 = userById.get("price2") + "";
			if (StringUtils.isEmpty(price1) || "0.0000".equals(price1) || StringUtils.isEmpty(price2)
					|| "0.0000".equals(price2)) {
				return rb.rollback("关键词报价为空");
			}
			List<Map<String, Object>> successList = new ArrayList<>();
			List<Map<String, Object>> failList = new ArrayList<>();
			for (int i = 0; i < engineCodes.length; i++) {
				for (int j = 0; j < domains.size(); j++) {
					for (int y = 0; y < keyWords.size(); y++) {
						String kw = keyWords.get(y).trim();
						int num = keywordMapper.getkeyWordConfig(kw);
						Map<String, Object> pa = new HashMap<>();
						String price = "";

						if ("01".equals(engineCodes[i])) {
							pa.put("engineCodes", "百度PC");
							if (num != 0) {
								price = price1;
							} else {
								price = price2;
							}
						}
						if ("02".equals(engineCodes[i])) {
							pa.put("engineCodes", "百度移动");
							if (num != 0) {
								price = price1;
							} else {
								price = price2;
							}
						}
						if ("03".equals(engineCodes[i])) {
							pa.put("engineCodes", "360PC");
							if (num != 0) {
								price = price1;
							} else {
								price = price2;
							}
						}
						if ("04".equals(engineCodes[i])) {
							pa.put("engineCodes", "360移动");
							if (num != 0) {
								price = price1;
							} else {
								price = price2;
							}
						}
						if ("05".equals(engineCodes[i])) {
							pa.put("engineCodes", "神马");
							if (num != 0) {
								price = price1;
							} else {
								price = price2;
							}
						}
						if ("06".equals(engineCodes[i])) {
							pa.put("engineCodes", "搜狗pc");
							if (num != 0) {
								price = price1;
							} else {
								price = price2;
							}
						}
						if ("07".equals(engineCodes[i])) {
							pa.put("engineCodes", "搜狗移动");
							if (num != 0) {
								price = price1;
							} else {
								price = price2;
							}
						}
						pa.put("price", price);
						pa.put("keyWord", kw);
						pa.put("userId", user.get("id"));
						if ("01".equals(type)) {
							pa.put("state", "01");
						} else {
							pa.put("state", "00");
						}
						pa.put("keywordIndex", KeyWordsIndex.getKeyWordsInde(kw, key, engineCodes[i]));
						pa.put("createId", createId);
						pa.put("engineCode", engineCodes[i]);
						pa.put("domain", domains.get(j));
						pa.put("realUserId", user.get("id"));
						int count = keywordMapper.getKeyWordNum(pa);
						if(count > 0) {
							failList.add(pa);
							continue;
						}
						keywordMapper.saveKeyWord(pa);
						successList.add(pa);
						Map<String,Object> m = new HashMap<>();
						m.put("keywords_id", pa.get("id"));
						m.put("parentId", "0");
						m.put("userId", user.get("id"));
						m.put("price", price);
						m.put("create_id", createId);
						keywordMapper.saveKeyWordRelation(m);
					}
				}
			}
			rb.put("successList", successList);
			rb.put("failList", failList);
		} catch (Exception e) {
			log.info("代理用户添加关键词异常--- e={}", e);
			return rb.rollback("关键词域名重复");
		}
		return rb.success();
	}

	/**
	 * 普通用户添加关键词
	 * 
	 * @param param
	 *            param
	 * @return String
	 */
	public ReturnBody saveKeyWordAdmin(Map<String, Object> param) {
		log.info("普通用户添加关键词开始--- param={}", param);
		ReturnBody rb = ReturnBody.init();
		String keyWord = param.get("keyWord") + "";
		String domain = param.get("domain") + "";
		String userId = param.get("userId") + "";
		String createId = param.get("createId") + "";
		String engineCode = param.get("engineCode") + "";
		Map<String, Object> userById = userService.getUserById(Integer.parseInt(userId));
		if(userById == null || userById.isEmpty()) {
			rb.getResult().setIsRollBack("01");
			return rb;
		}
		String parentId = userById.get("parentId")+"";
		if(StringUtils.isEmpty(parentId) || !"0".equals(parentId)) {
			return rb.rollback("用户等级有误，请用新版添加!");
		}
		rb.run(CommonUtil.isUrlGroup(domain));
		if (!rb.isSuccess()) {
			rb.getResult().setIsRollBack("01");
			return rb;
		}
		rb.run(CommonUtil.isKeywordGroup(keyWord, "\n"));
		if (!rb.isSuccess()) {
			rb.getResult().setIsRollBack("01");
			return rb;
		}
		List<String> domains = rb.getCollection("urlList", String.class);
		List<String> keyWordList = rb.getCollection("keywordList", String.class);
		engineCode = engineCode.substring(0, engineCode.length() - 1);
		if (StringUtils.isEmpty(keyWord) || StringUtils.isEmpty(domain) || StringUtils.isEmpty(userId)
				|| StringUtils.isEmpty(createId) || StringUtils.isEmpty(engineCode)) {
			return rb.rollback("参数不能为空");
		}
		String[] engineCodes = engineCode.split(",");
		try {
			List<Map<String, Object>> keyWordOffer = getKeyWordOffer(keyWordList, "00", 1, engineCodes);
			if (keyWordOffer == null || keyWordOffer.size() == 0) {
				return rb.rollback("关键词报价为空");
			}
			List<Map<String, Object>> successList = new ArrayList<>();
			List<Map<String, Object>> failList = new ArrayList<>();
			for (int i = 0; i < engineCodes.length; i++) {
				for (int j = 0; j < domains.size(); j++) {
					for (Map<String, Object> map : keyWordOffer) {
						Map<String, Object> pa = new HashMap<>();
						String price = "";
						String keywordIndex = "";
						String keyWords = "";
						if ("01".equals(engineCodes[i])) {
							pa.put("engineCodes", "百度PC");
							price = map.get("BaiduPc") + "";
							keywordIndex = map.get("BaiduPcI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("02".equals(engineCodes[i])) {
							pa.put("engineCodes", "百度移动");
							price = map.get("BaiduMobile") + "";
							keywordIndex = map.get("BaiduMobileI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("03".equals(engineCodes[i])) {
							pa.put("engineCodes", "360PC");
							price = map.get("so") + "";
							keywordIndex = map.get("soI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("04".equals(engineCodes[i])) {
							pa.put("engineCodes", "360移动");
							price = map.get("so") + "";
							keywordIndex = map.get("soI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("05".equals(engineCodes[i])) {
							pa.put("engineCodes", "神马");
							price = map.get("shenma") + "";
							keywordIndex = map.get("shenmaI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("06".equals(engineCodes[i])) {
							pa.put("engineCodes", "搜狗pc");
							price = map.get("SogouPc") + "";
							keywordIndex = map.get("SogouPcI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("07".equals(engineCodes[i])) {
							pa.put("engineCodes", "搜狗移动");
							price = map.get("SogouMobile") + "";
							keywordIndex = map.get("SogouMobileI") + "";
							keyWords = map.get("keyWord") + "";
						}
						pa.put("price", price);
						pa.put("keywordIndex", keywordIndex);
						pa.put("keyWord", keyWords);
						pa.put("userId", userId);
						pa.put("createId", createId);
						pa.put("engineCode", engineCodes[i]);
						pa.put("domain", domains.get(j));
						pa.put("state", "00");
						pa.put("realUserId", userId);
						int count = keywordMapper.getKeyWordNum(pa);
						if(count > 0) {
							failList.add(pa);
							continue;
						}
						keywordMapper.saveKeyWord(pa);
						successList.add(pa);
						Map<String,Object> m = new HashMap<>();
						m.put("keywords_id", pa.get("id"));
						m.put("parentId", "0");
						m.put("userId", userId);
						m.put("price", price);
						m.put("create_id", createId);
						keywordMapper.saveKeyWordRelation(m);
					}
				}
			}
			rb.put("successList", successList);
			rb.put("failList", failList);
		} catch (Exception e) {
			log.info("普通用户添加关键词异常--- e={}", e);
			return rb.rollback("关键词域名重复");
		}
		return rb.success();
	}

	@Override
	public ReturnBody saveKeyWordProxy(Map<String, Object> param, String uploadType) {
		log.info("添加关键词开始--- param={}", param);
		ReturnBody rb = ReturnBody.init();
		if (param == null || param.isEmpty()) {
			return rb.rollback("参数不能为空");
		}
		try {
			String userName = (String) param.get("userName");
			if (StringUtils.isEmpty(userName)) {
				rb.run(keywordServiceMap.get(uploadType).saveKeyWord1(param, "02"));
			} else {
				Map<String, Object> user = proxyUserMapper.getProxyUserByUserName(param);
				if (user == null || !"01".equals(user.get("state"))) {
					return rb.rollback("用户不存在");
				}
				param.put("proxyUser", user);
				String price1 = user.get("price1") + "";
				String price2 = user.get("price2") + "";
				if (!StringUtils.isEmpty(price1) && !"0.0000".equals(price1) && !StringUtils.isEmpty(price2)
						&& !"0.0000".equals(price2)) {
					param.put("price1", price1);
					param.put("price2", price2);
					rb.run(keywordServiceMap.get(uploadType).saveKeyWordProxy2(param));
					return rb;
				} else {
					rb.run(keywordServiceMap.get(uploadType).saveKeyWordProxy1(param));
				}
			}
			return rb;
		} catch (Exception e) {
			e.printStackTrace();
			log.info("添加关键词异常--- e={}", e);
			return rb.rollback("关键词域名重复");
		} finally {
			if (!rb.isSuccess()) {
				rb.result();
			}
			log.info("添加关键词结束--- res={}", rb);
		}
		
	}

	@SuppressWarnings("unchecked")
	public ReturnBody saveKeyWordProxy2(Map<String, Object> param) {
		log.info("代理三方用户添加关键词开始--- param={}", param);
		ReturnBody rb = ReturnBody.init();
		Map<String, Object> proxyUser = (Map<String, Object>) param.get("proxyUser");
		Map<String, Object> user = (Map<String, Object>) param.get("user");
		String keyWord = param.get("keyWord") + "";
		String domain = param.get("domain") + "";
		String userId = param.get("userId") + "";
		String proxyId = proxyUser.get("id") + "";
		String engineCode = param.get("engineCode") + "";
		engineCode = engineCode.substring(0, engineCode.length() - 1);
		if (StringUtils.isEmpty(keyWord) || StringUtils.isEmpty(domain) || StringUtils.isEmpty(userId)
				|| StringUtils.isEmpty(proxyId) || StringUtils.isEmpty(engineCode) || user == null) {
			return rb.rollback("参数不能为空");
		}
		
		Map<String, Object> userById = userService.getUserById(Integer.parseInt(userId));
		if(userById == null || userById.isEmpty()) {
			rb.getResult().setIsRollBack("01");
			return rb;
		}
		String parentId = userById.get("parentId")+"";
		if(StringUtils.isEmpty(parentId) || !"0".equals(parentId)) {
			return rb.rollback("用户等级有误，请用新版添加!");
		}
		
		rb.run(CommonUtil.isUrlGroup(domain));
		
		if (!rb.isSuccess()) {
			rb.getResult().setIsRollBack("01");
			return rb;
		}
		rb.run(CommonUtil.isKeywordGroup(keyWord, "\n"));
		if (!rb.isSuccess()) {
			rb.getResult().setIsRollBack("01");
			return rb;
		}
		List<String> domains = rb.getCollection("urlList", String.class);
		List<String> keyWordList = rb.getCollection("keywordList", String.class);
		
		String[] engineCodes = engineCode.split(",");
		String price1 = user.get("price1") + "";
		String price2 = user.get("price2") + "";
		if (StringUtils.isEmpty(price1) || "0.0000".equals(price1) || StringUtils.isEmpty(price2)
				|| "0.0000".equals(price2)) {
			return rb.rollback("关键词报价为空");
		}
		String price11 = proxyUser.get("price1") + "";
		String price22 = proxyUser.get("price2") + "";
		if (StringUtils.isEmpty(price1) || "0.0000".equals(price1) || StringUtils.isEmpty(price2)
				|| "0.0000".equals(price2)) {
			return rb.rollback("关键词报价为空");
		}
		try {
			
			List<Map<String, Object>> successList = new ArrayList<>();
			List<Map<String, Object>> failList = new ArrayList<>();
			for (int i = 0; i < engineCodes.length; i++) {
				for (int j = 0; j < domains.size(); j++) {
					for (int y = 0; y < keyWordList.size(); y++) {
						String kw = keyWordList.get(y).trim();
						int num = keywordMapper.getkeyWordConfig(kw);
						Map<String, Object> pa = new HashMap<>();
						String price = "";
						String proxyPrice = "";
						if ("01".equals(engineCodes[i])) {
							pa.put("engineCodes", "百度PC");
							if (num == 0) {
								price = price2;
								proxyPrice = price22;
							} else {
								price = price1;
								proxyPrice = price11;
							}
						}
						if ("02".equals(engineCodes[i])) {
							pa.put("engineCodes", "百度移动");
							if (num == 0) {
								price = price2;
								proxyPrice = price22;
							} else {
								price = price1;
								proxyPrice = price11;
							}
						}
						if ("03".equals(engineCodes[i])) {
							pa.put("engineCodes", "360PC");
							if (num == 0) {
								price = price2;
								proxyPrice = price22;
							} else {
								price = price1;
								proxyPrice = price11;
							}
						}
						if ("04".equals(engineCodes[i])) {
							pa.put("engineCodes", "360移动");
							if (num == 0) {
								price = price2;
								proxyPrice = price22;
							} else {
								price = price1;
								proxyPrice = price11;
							}
						}
						if ("05".equals(engineCodes[i])) {
							pa.put("engineCodes", "神马");
							if (num == 0) {
								price = price2;
								proxyPrice = price22;
							} else {
								price = price1;
								proxyPrice = price11;
							}
						}
						if ("06".equals(engineCodes[i])) {
							pa.put("engineCodes", "搜狗pc");
							if (num == 0) {
								price = price2;
								proxyPrice = price22;
							} else {
								price = price1;
								proxyPrice = price11;
							}
						}
						if ("07".equals(engineCodes[i])) {
							pa.put("engineCodes", "搜狗移动");
							if (num == 0) {
								price = price2;
								proxyPrice = price22;
							} else {
								price = price1;
								proxyPrice = price11;
							}
						}
						pa.put("price", price);
						pa.put("proxyPrice", proxyPrice);
						pa.put("keywordIndex", KeyWordsIndex.getKeyWordsInde(kw, key, engineCodes[i]));
						pa.put("keyWord", kw);
						pa.put("userId", userId);
						pa.put("realUserId", userId);
						pa.put("proxyId", proxyId);
						pa.put("engineCode", engineCodes[i]);
						pa.put("domain", domains.get(j));
						int count = keywordMapper.getKeyWordNum(pa);
						if(count > 0) {
							failList.add(pa);
							continue;
						}
						keywordMapper.saveKeyWord(pa);
						keywordMapper.saveKeyWordProxy(pa);
						successList.add(pa);
						Map<String,Object> m = new HashMap<>();
						m.put("keywords_id", pa.get("id"));
						m.put("parentId", "0");
						m.put("userId", userId);
						m.put("price", price);
						m.put("create_id", userId);
						keywordMapper.saveKeyWordRelation(m);
					}
				}
			}
			rb.put("successList", successList);
			rb.put("failList", failList);
		} catch (Exception e) {
			log.info("代理三方用户添加关键词异常--- e={}", e);
			return rb.rollback("关键词域名重复");
		}
		return rb.success();
	}

	@SuppressWarnings("unchecked")
	public ReturnBody saveKeyWordProxy1(Map<String, Object> param) {
		log.info("代理三方用户添加关键词开始--- param={}", param);
		ReturnBody rb = ReturnBody.init();
		Map<String, Object> proxyUser = (Map<String, Object>) param.get("proxyUser");
		Map<String, Object> user = (Map<String, Object>) param.get("user");
		String keyWord = param.get("keyWord") + "";
		String domain = param.get("domain") + "";
		String userId = param.get("userId") + "";
		String proxyId = proxyUser.get("id") + "";
		String engineCode = param.get("engineCode") + "";
		engineCode = engineCode.substring(0, engineCode.length() - 1);
		if (StringUtils.isEmpty(keyWord) || StringUtils.isEmpty(domain) || StringUtils.isEmpty(userId)
				|| StringUtils.isEmpty(proxyId) || StringUtils.isEmpty(engineCode) || user == null) {
			return rb.rollback("参数不能为空");
		}
		
		Map<String, Object> userById = userService.getUserById(Integer.parseInt(userId));
		if(userById == null || userById.isEmpty()) {
			rb.getResult().setIsRollBack("01");
			return rb;
		}
		String parentId = userById.get("parentId")+"";
		if(StringUtils.isEmpty(parentId) || !"0".equals(parentId)) {
			return rb.rollback("用户等级有误，请用新版添加!");
		}
		
		rb.run(CommonUtil.isUrlGroup(domain));
		
		if (!rb.isSuccess()) {
			rb.getResult().setIsRollBack("01");
			return rb;
		}
		rb.run(CommonUtil.isKeywordGroup(keyWord, "\n"));
		if (!rb.isSuccess()) {
			rb.getResult().setIsRollBack("01");
			return rb;
		}
		List<String> domains = rb.getCollection("urlList", String.class);
		List<String> keyWordList = rb.getCollection("keywordList", String.class);
		
		String[] engineCodes = engineCode.split(",");
		String price1 = user.get("price1") + "";
		String price2 = user.get("price2") + "";
		if (StringUtils.isEmpty(price1) || "0.0000".equals(price1) || StringUtils.isEmpty(price2)
				|| "0.0000".equals(price2)) {
			return rb.rollback("关键词报价为空");
		}
		try {
			List<Map<String, Object>> keyWordOffer = getKeyWordOffer(keyWordList, "01", Integer.parseInt(userId), engineCodes);
			if (keyWordOffer == null || keyWordOffer.size() == 0) {
				return rb.rollback("关键词报价为空");
			}
			List<Map<String, Object>> successList = new ArrayList<>();
			List<Map<String, Object>> failList = new ArrayList<>();
			for (int i = 0; i < engineCodes.length; i++) {
				for (int j = 0; j < domains.size(); j++) {
					for (Map<String, Object> map : keyWordOffer) {
						Map<String, Object> pa = new HashMap<>();
						String keyWords = map.get("keyWord") + "";
						int num = keywordMapper.getkeyWordConfig(keyWords);
						String proxyPrice = "";
						String keywordIndex = "";
						String price = "";
						if ("01".equals(engineCodes[i])) {
							pa.put("engineCodes", "百度PC");
							if (num == 0) {
								price = price2;
							} else {
								price = price1;
							}
							proxyPrice = map.get("BaiduPc") + "";
							keywordIndex = map.get("BaiduPcI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("02".equals(engineCodes[i])) {
							pa.put("engineCodes", "百度移动");
							if (num == 0) {
								price = price2;
							} else {
								price = price1;
							}
							proxyPrice = map.get("BaiduMobile") + "";
							keywordIndex = map.get("BaiduMobileI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("03".equals(engineCodes[i])) {
							pa.put("engineCodes", "360PC");
							if (num == 0) {
								price = price2;
							} else {
								price = price1;
							}
							proxyPrice = map.get("so") + "";
							keywordIndex = map.get("soI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("04".equals(engineCodes[i])) {
							pa.put("engineCodes", "360移动");
							if (num == 0) {
								price = price2;
							} else {
								price = price1;
							}
							proxyPrice = map.get("so") + "";
							keywordIndex = map.get("soI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("05".equals(engineCodes[i])) {
							pa.put("engineCodes", "神马");
							if (num == 0) {
								price = price2;
							} else {
								price = price1;
							}
							proxyPrice = map.get("shenma") + "";
							keywordIndex = map.get("shenmaI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("06".equals(engineCodes[i])) {
							pa.put("engineCodes", "搜狗pc");
							if (num == 0) {
								price = price2;
							} else {
								price = price1;
							}
							proxyPrice = map.get("SogouPc") + "";
							keywordIndex = map.get("SogouPcI") + "";
							keyWords = map.get("keyWord") + "";
						}
						if ("07".equals(engineCodes[i])) {
							pa.put("engineCodes", "搜狗移动");
							if (num == 0) {
								price = price2;
							} else {
								price = price1;
							}
							proxyPrice = map.get("SogouMobile") + "";
							keywordIndex = map.get("SogouMobileI") + "";
							keyWords = map.get("keyWord") + "";
						}
						pa.put("price", price);
						pa.put("proxyPrice", proxyPrice);
						pa.put("keywordIndex", keywordIndex);
						pa.put("keyWord", keyWords);
						pa.put("userId", userId);
						pa.put("realUserId", userId);
						pa.put("proxyId", proxyId);
						pa.put("engineCode", engineCodes[i]);
						pa.put("domain", domains.get(j));
						int count = keywordMapper.getKeyWordNum(pa);
						if(count > 0) {
							failList.add(pa);
							continue;
						}
						keywordMapper.saveKeyWord(pa);
						keywordMapper.saveKeyWordProxy(pa);
						successList.add(pa);
						Map<String,Object> m = new HashMap<>();
						m.put("keywords_id", pa.get("id"));
						m.put("parentId", "0");
						m.put("userId", userId);
						m.put("price", price);
						m.put("create_id", userId);
						keywordMapper.saveKeyWordRelation(m);
					}
				}
			}
			rb.put("successList", successList);
			rb.put("failList", failList);
		} catch (Exception e) {
			log.info("代理三方用户添加关键词异常--- e={}", e);
			return rb.rollback("关键词域名重复");
		}
		return rb.success();
	}

	@Override
	public List<Map<String, Object>> getKeyWordOffer() {
		return keywordMapper.getKeyWordOffer();
	}

	@Override
	public ReturnBody saveIndex(Map<String, Object> params) {
		ReturnBody rb = ReturnBody.init();
		int num = keywordMapper.saveIndex(params);
		if (num == 0) {
			return rb.error("error", "保存失败");
		}
		return rb.success();
	}

	@Override
	public Map<String, Object> getIndexById(Integer id) {
		return keywordMapper.getIndexById(id);
	}

	@Override
	public ReturnBody updateIndex(Map<String, Object> params) {
		ReturnBody rb = ReturnBody.init();
		int num = keywordMapper.updateIndex(params);
		if (num == 0) {
			return rb.error("error", "修改失败");
		}
		return rb.success();
	}

	@Override
	public int deleteIndex(Integer id) {
		return keywordMapper.deleteIndex(id);
	}

	@Override
	public List<Map<String, Object>> getKeyWordIndexProxy(Integer userId) {
		return keywordMapper.getKeyWordIndexProxy(userId);
	}

	@Override
	public Map<String, Object> getProxyIndexById(Integer id) {
		return keywordMapper.getProxyIndexById(id);
	}

	@Override
	public ReturnBody saveProxyIndex(Map<String, Object> params) {
		ReturnBody rb = ReturnBody.init();
		int num = keywordMapper.saveProxyIndex(params);
		if (num == 0) {
			return rb.error("error", "修改失败");
		}
		return rb.success();
	}

	@Override
	public List<Map<String, Object>> getKeywordGroupList(Map<String, Object> params) {
		return keywordMapper.getKeywordGroupList(params);
	}

	@Override
	public int saveGroup(Map<String, Object> params) {
		return keywordMapper.saveGroup(params);
	}

	@Override
	public int getKeywordGroupNum(Integer id) {
		return keywordMapper.getKeywordGroupNum(id);
	}

	@Override
	public int deleteGroup(Integer id) {
		return keywordMapper.deleteGroup(id);
	}

	@Override
	public int updateGroup(Map<String, Object> params) {
		return keywordMapper.updateGroup(params);
	}

	public void put(String key, KeywordServiceImpl service) {
		keywordServiceMap.put(key, service);
	}

	@Override
	public List<Map<String, Object>> getRecycleBinList(Map<String, Object> params) {
		return keywordMapper.getRecycleBinList(params);
	}
	
	
	@Override
	public int getRecycleBinCnt(Map<String, Object> params) {
		return keywordMapper.getRecycleBinCnt(params);
	}

	@Override
	public int keyWordUpdate(Map<String, Object> pam) {
		return keywordMapper.updateKeyWordD(pam);
	}

	@Override
	public int deleteK(Map<String, Object> pam) {
		keywordMapper.deleteK(pam);
		keywordMapper.deleteK1(pam);
		keywordMapper.deleteKeyWordR(pam);
		return 1;
	}
	
}